package collect.map;

import java.util.*;

public class TestNumberr {
    public static void main(String[] args) {
        //创建列表
        String[] place = {"A", "B", "C", "D"};
        Random r = new Random();
        //创建容器
        ArrayList<String> list = new ArrayList<>();
        //模拟80次选择并把选择存入容器
        for (int i = 0; i < 80; i++) {
            int index = r.nextInt(place.length);
            list.add(place[index]);
        }
        //定义Map查数
        HashMap<String, Integer> map = new HashMap<>();
        for (String name : list) {
            //判断键是否已经存在
            if (map.containsKey(name)) {
                //存在
                Integer integer = map.get(name);
                integer++;
                map.put(name, integer);
            } else {
                //不存在
                map.put(name, 1);
            }
        }
        //判断最大值
        int max = 0;
        Set<Map.Entry<String, Integer>> entries = map.entrySet();
        for (Map.Entry<String, Integer> entry : entries) {
            Integer value = entry.getValue();
            if (value > max) {
                max = value;
            }
        }
        System.out.println(max);
        //判断是否有两个景点人数一样多
        for (Map.Entry<String, Integer> entry : entries) {
            Integer value = entry.getValue();
            if (value == max) {
                String key = entry.getKey();
                System.out.println("票数最多的景点是：" + key +
                        "票数为：" + max);
            }
        }


    }
}
